package com.example.app2024.navigationButtom;

import androidx.lifecycle.ViewModelProvider;

import android.animation.ObjectAnimator;
import android.os.Bundle;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;

import com.example.app2024.R;

public class OneFragment extends Fragment
{

      private OneViewModel mViewModel;
      private ImageView imageView;

      public static OneFragment newInstance()
      {
            return new OneFragment();
      }

      @Override
      public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState)
      {
            View view = inflater.inflate(R.layout.fragment_one, container, false);
            imageView = view.findViewById(R.id.imageView);
            return  view;
      }

      @Override
      public void onActivityCreated(@Nullable Bundle savedInstanceState)
      {
            super.onActivityCreated(savedInstanceState);
            mViewModel = new ViewModelProvider(requireActivity()).get(OneViewModel.class);
            imageView.setRotation(mViewModel.rotationPosition);
            // TODO: Use the ViewModel
            ObjectAnimator objectAnimator = ObjectAnimator.ofFloat(imageView, "rotation",0, 0 , 0 , 0 );
            objectAnimator.setDuration(500);
            imageView.setOnClickListener(v -> {
                  if (!objectAnimator.isRunning())
                  {
                        objectAnimator.setFloatValues(imageView.getRotation(), imageView.getRotation()+100);
                        mViewModel.rotationPosition += 100;
                        objectAnimator.start();
                  }
            });

      }

}